//
//  LSZSecondaryLiteratureDetailsVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/24.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZSecondaryLiteratureDetailsVC.h"

@interface LSZSecondaryLiteratureDetailsVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UITableView * tableViewInformation;
@property(nonatomic,strong) NSMutableArray * mutArrayData;

@end

@implementation LSZSecondaryLiteratureDetailsVC
-(void)getDataWithID
{
    [LSZRequestDicData threeInterfaceForData:self.id_id :^(BOOL isOk, NSString * string, LSZTertiaryInterfaceManager * manager) {
        if (isOk == YES) {
            [self.mutArrayData addObjectsFromArray:manager.arrayData];
            [self.tableViewInformation reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZSecondaryLiteratureDetailsVC"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZSecondaryLiteratureDetailsVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.titleString;
    [self addNotificationCenter];
    self.mutArrayData = [[NSMutableArray alloc]init];
    [self.tableViewInformation registerClass:[LSZDocumentdetailsCell class] forCellReuseIdentifier:@"LSZDocumentdetailsCell"];
    [self.tableViewInformation registerClass:[LSZHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZHeaderCell"];
    [self getDataWithID];
    __weak typeof(self) weakSelf = self;
    [self.tableViewInformation addRefreshHeaderWithHandle:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 刷新表格  和结束刷新
            [weakSelf.tableViewInformation.mj_header endRefreshing];
        });
    }];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 200;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.mutArrayData.count > indexPath.row) {
//        LSZTertiaryInterfaceMg * mg = nil;
//        mg = self.mutArrayData[indexPath.row];
//        CGFloat height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-50-100 height:ScreenHeight*10 font:16 :mg.name];
//        return 47+height;
        return 100;
    }
    return 0.0001;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LSZHeaderCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZHeaderCell"];
    [cell.imageViewOver sd_setImageWithURL:[NSURL URLWithString:self.urlImageView] placeholderImage:[UIImage imageNamed:@"默认"]];
    return cell;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZDocumentdetailsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZDocumentdetailsCell" forIndexPath:indexPath];
    if (self.mutArrayData.count > indexPath.row) {
        LSZTertiaryInterfaceMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
//        cell.labelNum.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row+1];
        cell.tertiaryInterfaceMg = mg;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.mutArrayData.count > indexPath.row) {
        LSZTertiaryInterfaceMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        LSZDirectoryDetailsViewController * vc = [[LSZDirectoryDetailsViewController alloc]init];
        vc.url = mg.contentUrl;
        vc.productID = mg.id_id;
        vc.imageViewStr = self.urlImageView;
        vc.titleStr = mg.name;
        vc.publishTime = mg.publishTime;
        vc.period = @"20";
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(UITableView *)tableViewInformation
{
    if (_tableViewInformation == nil) {
        _tableViewInformation = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height) style:UITableViewStyleGrouped];
        _tableViewInformation.delegate = self;
        _tableViewInformation.dataSource = self;
        _tableViewInformation.estimatedRowHeight=0;
        _tableViewInformation.estimatedSectionFooterHeight =0;
        _tableViewInformation.estimatedSectionHeaderHeight =0;
        [_tableViewInformation setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewInformation
         ];
    }
    return _tableViewInformation;
}

@end
